<template>
	<view class="">
				<!-- 默认 -->
		<template v-if="type==1">
			<swiper class="image-container" circular autoplay @change="swiperChange">
				<swiper-item class="vw" :class="currentIndex == index ? 'swiper-item' : 'swiper-item-side'"
					v-for="(item, index) in imgList" :key="item[urlKey]">
					<image  class="vw" @click="clickImg(item)" :class="currentIndex == index ? 'item-img' : 'item-img-side'"
						:src="item[urlKey]" lazy-load :style="dontFirstAnimation ? 'animation: none;' : ''"
						mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</template>
				<!-- 漏头尾 autoplay-->
		<template v-else>
			<swiper class="image-container" :previous-margin="previousMargin" :next-margin="nextMargin" autoplay circular 
				@change="swiperChange" :style="'height:'+itemHeight+'rpx'" >
				<swiper-item :class="currentIndex == index ? 'swiper-item' : 'swiper-item-side'"
					v-for="(item, index) in imgList" :key="item[urlKey]">
					<image @click="clickImg(item)" :class="currentIndex == index ? 'item-img' : 'item-img-side'"
						:src="item[urlKey]" lazy-load :style="dontFirstAnimation ? 'animation: none;' : ''"
						mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</template>
	</view>
</template>
<script>
	export default {
		props: {
			imgList: {
				type: Array,
				default () {
					return []
				}
			},
			urlKey: {
				type: String,
				default () {
					return ''
				}
			},
			previousMargin: {
				type: String,
				default () {
					return '0px'
				}
			},
			nextMargin: {
				type: String,
				default () {
					return '0px'
				}
			},
			type: {
				type: String,
				default () {
					return '1'
				}
			},
			itemHeight: {
				type: Number,
				default () {
					return 300
				}
			},
		},
		computed: {
			// 计算 CSS 变量
			cssVars() {
				console.log(this.itemHeight);
				return {
					// '--shape-width': `${this.width}rpx`,
					'--shape-height': `${this.itemHeight}rpx`,
					// '--shape-bg-color': this.bgColor,
					// '--shape-angle': `${this.angle}deg`
				}
			}
		},
		data() {
			return {
				currentIndex: 0,
				dontFirstAnimation: true
			}
		},
		methods: {
			swiperChange(e) {
				this.dontFirstAnimation = false
				this.currentIndex = e.detail.current
			},
			clickImg(item) {
				this.$emit('selected', item, this.currentIndex)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.image-container {
		width: 750rpx;
		height: 350rpx;
	}

	.item-img {
		width: 630rpx;
		/* width: 100%; */
		height:100%;
		border-radius: 14rpx;
		animation: to-big .5s;
	}

	.swiper-item {
		width: 630rpx;
		height:100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.item-img-side {
		width: 630rpx;
		/* width: 100%; */
		height: 260rpx;
		border-radius: 14rpx;
		animation: to-mini .5s;
	}

	.swiper-item-side {
		width: 630rpx;
		height: 260rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.vw {
		width: 100% !important;
	}

	@keyframes to-mini {
		 0% { transform: scaleY(1); }
		  100% { transform: scaleY(0.8); }
		/* from {
			height: var(--shape-height);//300rpx;
		}

		to {
			height: 260rpx;
		} */
	}

	@keyframes to-big {
		 0% { transform: scaleY(0.8); }
		  100% { transform: scaleY(1); }
		/* from {
			height: 260rpx;
		}

		to {
			height: var(--shape-height);//300rpx;
		} */
	}
</style>